package com.siblings.loan.ui.loan.adapter

import android.view.LayoutInflater
import android.widget.LinearLayout
import androidx.recyclerview.widget.RecyclerView
import com.siblings.lib_baseadapter.SIBRecyclerViewAdapter
import com.siblings.lib_baseadapter.SIBViewHolderHelper
import com.siblings.loan.R
import com.siblings.loan.databinding.ItemOrderContentBinding
import com.siblings.loan.databinding.ItemOrderTitleBinding
import org.json.JSONObject

/**
 * Siblings
 * @Author wwdeng
 * @CreateTime: 2024/7/15 14:42
 * @Annotation：贷款订单 适配器
 */
class SibLoanOrderAdapter(recyclerView: RecyclerView?) : SIBRecyclerViewAdapter<JSONObject>(recyclerView, R.layout.item_order) {
    override fun setItemChildListener(helper: SIBViewHolderHelper, viewType: Int) {
        helper.setItemChildClickListener(R.id.btnRepay) //支付
    }

    override fun fillData(helper: SIBViewHolderHelper, position: Int, model: JSONObject) {
        val titleLayout = helper.getView<LinearLayout>(R.id.titleLayout)
        titleLayout.removeAllViews()
        val titleList = model.optJSONArray("titleList")
        if (titleList != null) {
            for (i in 0..<titleList.length()){
                val item = titleList.optJSONObject(i)
                val titleBinding = ItemOrderTitleBinding.inflate(LayoutInflater.from(mContext))
                titleBinding.textName.text = item.optString("showName")
                titleBinding.textContent.text = item.optString("showDetail")
                titleLayout.addView(titleBinding.root)
            }
        }


        val contentLayout = helper.getView<LinearLayout>(R.id.contentLayout)
        contentLayout.removeAllViews()
        val contentList = model.optJSONArray("contentList")
        if (contentList != null) {
            for (i in 0..<contentList.length()){
                val item = contentList.optJSONObject(i)
                val contentBinding = ItemOrderContentBinding.inflate(LayoutInflater.from(mContext))
                contentBinding.textName.text = item.optString("showName")
                contentBinding.textContent.text = item.optString("showDetail")
                contentLayout.addView(contentBinding.root)
            }
        }
    }
}